package com.example.blog.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.blog.dao.pojo.Tag;
import com.example.blog.vo.TagVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TagMapper extends BaseMapper<Tag> {

    @Select("select * from article_tag where tid in " +
            "(select tagId from article_blog_tag where articleId=#{articleID})")
    List<TagVo> findTagsByArticleId(Long articleId);

    @Select("SELECT tagId " +
            "FROM article_blog_tag " +
            "GROUP BY tagId " +
            "ORDER BY count(*) DESC " +
            "LIMIT #{limit} ")
    List<Long> finHostTageIds(int limit);

//    @Select("select * from article_tag where tid in fore #{tagIds}")
    @Select("<script>"
                        + "SELECT * FROM article_tag WHERE tid IN "
                        + "<foreach item='item' index='index' collection='tagIds' open='(' separator=',' close=')'>"
                            + "#{item}"
                        + "</foreach>"
                    + "</script>")
    List<Tag> findTagsByTagIds(List<Long> tagIds);

    @Select("select * from  article_tag order by createTime desc  " )
    List<Tag> findTagsNew();
}
